/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package medicalassistant;
import java.sql.*;
import javax.swing.table.*;
import java.text.*;
import javax.swing.event.*;
/**
 *
 * @author haozhang
 */
public class ManageNurser extends javax.swing.JPanel {

    /**
     * Creates new form ManageNurser
     */
    public ManageNurser(int ID, int userType, Connection connect) {
        initComponents();
        selectedNurse = -1;
        try {
            Class.forName("org.sqlite.JDBC");
            conn = connect;
            stat = conn.createStatement();
            System.out.println("SQLite connection successful!");
            ResultSet nurseRS;
            if (userType < 4)
                nurseRS = stat.executeQuery("SELECT * FROM nurses WHERE doctorID = " + ID);
            else
                nurseRS = stat.executeQuery("SELECT * FROM nurses");
            DefaultTableModel nurseModel = (DefaultTableModel) nurseList.getModel();
            while (nurseRS.next()) {
                nurseModel.addRow(new Object[]{nurseRS.getString(3), nurseRS.getString(2), nurseRS.getString(1)});
            }
        } catch(ClassNotFoundException ex) {System.out.println(ex.getMessage());}
        catch(SQLException ex) {System.out.println(ex.getMessage());}
        
        nurseList.getSelectionModel().addListSelectionListener(
        new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent event) {
                int rowSelected = nurseList.getSelectedRow();
                if (rowSelected < 0) {
                    nurseName.setText("[no nurse selected]");
                    address.setText("");
                    birth.setText("");
                    city.setText("");
                    firstName.setText("");
                    insurance.setText("");
                    insuranceID.setText("");
                    lastName.setText("");
                    ssn.setText("");
                    state.setText("");
                    zip.setText("");
                    sex.setSelectedItem("--");
                    title.setSelectedItem("--");
                    doctorID.setText("");
                }
                else {
                    TableModel model = nurseList.getModel();
                    selectedNurse = Integer.parseInt((String)model.getValueAt(rowSelected, 2));
                    System.out.println("Selected nurse ID " + selectedNurse);
                    try {
                        ResultSet patientInfo = stat.executeQuery("SELECT * FROM nurses WHERE uid = '" + selectedNurse + "';");
                        nurseName.setText(patientInfo.getString("first") + " " + patientInfo.getString("last") + " [" + selectedNurse + "]");
                        address.setText(patientInfo.getString("address"));
                        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                        birth.setText(df.format(patientInfo.getDate("birthdate")));
                        city.setText(patientInfo.getString("city"));
                        firstName.setText(patientInfo.getString("first"));
                        insurance.setText(patientInfo.getString("insurance"));
                        insuranceID.setText(patientInfo.getString("insuranceID"));
                        lastName.setText(patientInfo.getString("last"));
                        ssn.setText(patientInfo.getString("ssn"));
                        state.setText(patientInfo.getString("state"));
                        zip.setText(patientInfo.getString("zip"));
                        sex.setSelectedItem(patientInfo.getString("sex"));
                        title.setSelectedItem(patientInfo.getString("title"));
                        doctorID.setText(patientInfo.getString("doctorID"));
                    } catch (SQLException ex) {System.out.println(ex.getMessage());}
                }
                emptyError.setText("");
            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        nursePanels = new javax.swing.JPanel();
        nurseInfoPanel = new javax.swing.JPanel();
        patientsListPanel = new javax.swing.JPanel();
        patientsListHeader = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        patientsList = new javax.swing.JTable();
        nurseEntriesPanel = new javax.swing.JPanel();
        buttonsPanel = new javax.swing.JPanel();
        saveButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        firstName = new javax.swing.JTextField();
        birth = new javax.swing.JTextField();
        title = new javax.swing.JComboBox();
        lastName = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        ssn = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        address = new javax.swing.JTextArea();
        jLabel7 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        insurance = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        city = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        sex = new javax.swing.JComboBox();
        zip = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        doctorID = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        insuranceID = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        state = new javax.swing.JTextField();
        emptyError = new javax.swing.JLabel();
        birthError = new javax.swing.JLabel();
        nurseHeaderPanel = new javax.swing.JPanel();
        nurseName = new javax.swing.JLabel();
        nurseListPanel = new javax.swing.JPanel();
        nurseListLabel = new javax.swing.JLabel();
        jScrollPane = new javax.swing.JScrollPane();
        nurseList = new javax.swing.JTable();

        setLayout(new java.awt.BorderLayout());

        nursePanels.setLayout(new java.awt.BorderLayout());

        patientsListHeader.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        patientsListHeader.setText("Assigned Patients:");

        patientsList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Last Name", "First Name", "ID"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(patientsList);

        javax.swing.GroupLayout patientsListPanelLayout = new javax.swing.GroupLayout(patientsListPanel);
        patientsListPanel.setLayout(patientsListPanelLayout);
        patientsListPanelLayout.setHorizontalGroup(
            patientsListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(patientsListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(patientsListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(patientsListPanelLayout.createSequentialGroup()
                        .addComponent(patientsListHeader)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE))
                .addContainerGap())
        );
        patientsListPanelLayout.setVerticalGroup(
            patientsListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(patientsListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(patientsListHeader)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        saveButton.setText("Save");
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });
        buttonsPanel.add(saveButton);

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });
        buttonsPanel.add(cancelButton);

        jLabel3.setText("First Name:");

        title.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mr.", "Mrs.", "Ms.", "Miss.", "Master." }));

        jLabel16.setText("Title:");

        jLabel11.setText("SSN:");

        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        address.setColumns(20);
        address.setRows(5);
        jScrollPane2.setViewportView(address);

        jLabel7.setText("Address:");

        jLabel4.setText("Last Name:");

        jLabel12.setText("Birthdate:");

        jLabel8.setText("City:");

        jLabel13.setText("Insurance Company:");

        jLabel6.setText("Sex:");

        sex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Male", "Female" }));

        jLabel1.setText("Doctor ID:");

        jLabel10.setText("Zip:");

        jLabel9.setText("State:");

        jLabel14.setText("Insurance ID:");

        emptyError.setText(" ");

        birthError.setText(" ");

        javax.swing.GroupLayout nurseEntriesPanelLayout = new javax.swing.GroupLayout(nurseEntriesPanel);
        nurseEntriesPanel.setLayout(nurseEntriesPanelLayout);
        nurseEntriesPanelLayout.setHorizontalGroup(
            nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(buttonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                        .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3)
                                .addComponent(jLabel4)
                                .addComponent(jLabel7)
                                .addComponent(jLabel8)
                                .addComponent(jLabel10)
                                .addComponent(jLabel12)
                                .addComponent(jLabel13))
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, nurseEntriesPanelLayout.createSequentialGroup()
                                        .addComponent(birth, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(birthError))
                                    .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                                        .addComponent(zip, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel11))
                                    .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                                        .addComponent(city, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
                                        .addComponent(jLabel9))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, nurseEntriesPanelLayout.createSequentialGroup()
                                        .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                            .addComponent(doctorID, javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(insurance, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel14)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(state)
                                    .addComponent(insuranceID)
                                    .addComponent(ssn)))
                            .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                                        .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(lastName)
                                            .addComponent(firstName, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel16))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(sex, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(emptyError))
                                .addGap(0, 0, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        nurseEntriesPanelLayout.setVerticalGroup(
            nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nurseEntriesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(emptyError)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(firstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel16)
                        .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel6)
                    .addComponent(sex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(city, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(state, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(zip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(ssn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(birth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)
                    .addComponent(birthError))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(insurance, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14)
                    .addComponent(insuranceID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(nurseEntriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(doctorID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 36, Short.MAX_VALUE)
                .addComponent(buttonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout nurseInfoPanelLayout = new javax.swing.GroupLayout(nurseInfoPanel);
        nurseInfoPanel.setLayout(nurseInfoPanelLayout);
        nurseInfoPanelLayout.setHorizontalGroup(
            nurseInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(patientsListPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(nurseEntriesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        nurseInfoPanelLayout.setVerticalGroup(
            nurseInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nurseInfoPanelLayout.createSequentialGroup()
                .addComponent(nurseEntriesPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(patientsListPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        nursePanels.add(nurseInfoPanel, java.awt.BorderLayout.CENTER);

        nurseName.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        nurseName.setText("[no nurse selected]");

        javax.swing.GroupLayout nurseHeaderPanelLayout = new javax.swing.GroupLayout(nurseHeaderPanel);
        nurseHeaderPanel.setLayout(nurseHeaderPanelLayout);
        nurseHeaderPanelLayout.setHorizontalGroup(
            nurseHeaderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nurseHeaderPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(nurseName)
                .addContainerGap(294, Short.MAX_VALUE))
        );
        nurseHeaderPanelLayout.setVerticalGroup(
            nurseHeaderPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nurseHeaderPanelLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(nurseName)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        nursePanels.add(nurseHeaderPanel, java.awt.BorderLayout.NORTH);

        add(nursePanels, java.awt.BorderLayout.CENTER);

        nurseListLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        nurseListLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nurseListLabel.setText("Nurse List");
        nurseListLabel.setToolTipText("");
        nurseListLabel.setName(""); // NOI18N

        nurseList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Last Name", "First Name", "ID"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        nurseList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane.setViewportView(nurseList);

        javax.swing.GroupLayout nurseListPanelLayout = new javax.swing.GroupLayout(nurseListPanel);
        nurseListPanel.setLayout(nurseListPanelLayout);
        nurseListPanelLayout.setHorizontalGroup(
            nurseListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nurseListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(nurseListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nurseListLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        nurseListPanelLayout.setVerticalGroup(
            nurseListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(nurseListPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(nurseListLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 592, Short.MAX_VALUE)
                .addContainerGap())
        );

        add(nurseListPanel, java.awt.BorderLayout.WEST);
    }// </editor-fold>//GEN-END:initComponents

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        // revert back to original
        if (selectedNurse < 0) {
            address.setText("");
            birth.setText("");
            city.setText("");
            firstName.setText("");
            insurance.setText("");
            insuranceID.setText("");
            lastName.setText("");
            ssn.setText("");
            state.setText("");
            zip.setText("");
            sex.setSelectedItem("--");
            title.setSelectedItem("--");
            doctorID.setText("");
            emptyError.setText("");
        }
        else {
            try {
                ResultSet patientInfo = stat.executeQuery("SELECT * FROM nurses WHERE uid = '" + selectedNurse + "';");
                nurseName.setText(patientInfo.getString("first") + " " + patientInfo.getString("last") + " [" + selectedNurse + "]");
                address.setText(patientInfo.getString("address"));
                SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                birth.setText(df.format(patientInfo.getDate("birthdate")));
                city.setText(patientInfo.getString("city"));
                firstName.setText(patientInfo.getString("first"));
                insurance.setText(patientInfo.getString("insurance"));
                insuranceID.setText(patientInfo.getString("insuranceID"));
                lastName.setText(patientInfo.getString("last"));
                ssn.setText(patientInfo.getString("ssn"));
                state.setText(patientInfo.getString("state"));
                zip.setText(patientInfo.getString("zip"));
                sex.setSelectedItem(patientInfo.getString("sex"));
                title.setSelectedItem(patientInfo.getString("title"));
                doctorID.setText(patientInfo.getString("doctorID"));
                emptyError.setText("");
            } catch (SQLException ex) {System.out.println(ex.getMessage());}
        }
    }//GEN-LAST:event_cancelButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        String sexString = (String) sex.getSelectedItem();
        String titleString = (String) title.getSelectedItem();
        if (!address.getText().isEmpty() 
                && !birth.getText().isEmpty() 
                && !city.getText().isEmpty() 
                && !firstName.getText().isEmpty()
                && !lastName.getText().isEmpty()
                && !ssn.getText().isEmpty()
                && !state.getText().isEmpty()
                && !zip.getText().isEmpty()
                && !sexString.equals("--")
                && !titleString.equals("--")
                && !doctorID.getText().isEmpty()
                && !insurance.getText().isEmpty()
                && !insuranceID.getText().isEmpty()
                && selectedNurse > 0) {
            try {
                // Parse Birthdate
                SimpleDateFormat sdfm = new SimpleDateFormat("yyyy-MM-dd");
                java.util.Date date = sdfm.parse((String)birth.getText());
                java.sql.Date sqlDate = new Date(date.getTime());
                emptyError.setText("Nurse successfully updated.");
                stat.executeQuery("UPDATE nurses SET "
                        + " address = '" + address.getText()
                        + "', birthdate = " + sqlDate
                        + ", city = '" + city.getText()
                        + "', first = '" + firstName.getText()
                        + "', last = '" + lastName.getText()
                        + "', ssn = " + ssn.getText()
                        + ", state = '" + state.getText()
                        + "', zip = " + zip.getText()
                        + ", sex = '" + sexString
                        + "', title = '" + titleString
                        + "', doctorID = " + doctorID.getText()
                        + ", insurance = '" + insurance.getText()
                        + "', insuranceID = '" + insuranceID.getText()
                        + "' WHERE uid = " + selectedNurse);
            } catch (SQLException ex) {System.out.println(ex.getMessage());}
            catch (ParseException ex) {birthError.setText("You must format your birthdate in this format: YYYY-MM-DD");}
        }
        else
            emptyError.setText("ERROR: You must fill in ALL the fields.");
    }//GEN-LAST:event_saveButtonActionPerformed
    
    
    // SQLite Variable declaration
    private Connection conn;
    private Statement stat;
    private int selectedNurse;
    // End of SQLite Variable declaration
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea address;
    private javax.swing.JTextField birth;
    private javax.swing.JLabel birthError;
    private javax.swing.JPanel buttonsPanel;
    private javax.swing.JButton cancelButton;
    private javax.swing.JTextField city;
    private javax.swing.JTextField doctorID;
    private javax.swing.JLabel emptyError;
    private javax.swing.JTextField firstName;
    private javax.swing.JTextField insurance;
    private javax.swing.JTextField insuranceID;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField lastName;
    private javax.swing.JPanel nurseEntriesPanel;
    private javax.swing.JPanel nurseHeaderPanel;
    private javax.swing.JPanel nurseInfoPanel;
    private javax.swing.JTable nurseList;
    private javax.swing.JLabel nurseListLabel;
    private javax.swing.JPanel nurseListPanel;
    private javax.swing.JLabel nurseName;
    private javax.swing.JPanel nursePanels;
    private javax.swing.JTable patientsList;
    private javax.swing.JLabel patientsListHeader;
    private javax.swing.JPanel patientsListPanel;
    private javax.swing.JButton saveButton;
    private javax.swing.JComboBox sex;
    private javax.swing.JTextField ssn;
    private javax.swing.JTextField state;
    private javax.swing.JComboBox title;
    private javax.swing.JTextField zip;
    // End of variables declaration//GEN-END:variables
}
